home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / amislate / slaterexx / surround.rexx < prev    next >
OS/2 REXX Batch file  |  1995-08-05  |  3KB  |  136 lines

  1.  
  2. /* Tron/Surround game for AmiSlate.  Use arrowkeys! */
  3.  
  4. /* Constants for use with AmiSlate's ARexx interface */
  5. AMode.DOT      =  0 
  6. AMode.PEN      =  1 
  7. AMode.LINE     =  2 
  8. AMode.CIRCLE   =  3 
  9. AMode.SQUARE   =  4 
  10. AMode.POLY     =  5 
  11. AMode.FLOOD    =  6 
  12. AMode.CLEAR    =  7 
  13.  
  14. AMessage.TIMEOUT     = 1        /* No events occurred in specified time period */
  15. AMessage.MESSAGE     = 2        /* Message recieved from remote Amiga */
  16. AMessage.MOUSEDOWN   = 4        /* Left mouse button press in drawing area */
  17. AMessage.MOUSEUP     = 8        /* Left mouse button release in drawing area */
  18. AMessage.RESIZE      = 16       /* Window was resized--time to redraw screen? */ 
  19. AMessage.QUIT        = 32       /* AmiSlate is shutting down */
  20. AMessage.CONNECT     = 64       /* Connection established */
  21. AMessage.DISCONNECT  = 128      /* Connection broken */
  22. AMessage.TOOLSELECT  = 256      /* Tool Selected */
  23. AMessage.COLORSELECT = 512      /* Palette Color selected */
  24. AMessage.KEYPRESS    = 1024     /* Key pressed */
  25. AMessage.MOUSEMOVE   = 2048     /* Mouse was moved */
  26.  
  27. /* Get our host's name--always given as first argument when run from Amislate */
  28. parse arg CommandPort ActiveString
  29.  
  30. if (length(CommandPort) == 0) then do
  31.         say ""
  32.         say "Usage:  rx surround.rexx <REXXPORTNAME>"
  33.         say "        (REXXPORTNAME is usually AMISLATE)"
  34.         say ""
  35.         say "Or run from the Rexx menu within AmiSlate."
  36.         say ""
  37.         exit 0
  38.         end
  39.  
  40. /* very important! */
  41. options results
  42.  
  43. /* Send all commands to this host */
  44. address (CommandPort) 
  45.  
  46. /* Initialize pen */
  47. penreset
  48.  
  49. /* Get Window size */
  50. setfpen 1
  51.  
  52. /* Draw a black box around the window border */
  53. GetWindowAttrs stem win.
  54.  
  55. /* Note that GetWindowAttrs returns the size of the whole window including
  56.    the ToolBar, Palette, Chat Lines, Title, and everything else.  To just
  57.    draw to the border of the drawing area, we need to subtract the constants
  58.    below.  */
  59. square 0 0 (win.width - 58) (win.height - 53)
  60.  
  61. /* Calculate center of drawing area */
  62. mx = trunc((win.width-58)/2)
  63. my = trunc((win.height-53)/2)
  64.  
  65. /* Seed random number generator */
  66. call randu(time('s'))
  67.  
  68. /* Determine random starting area */
  69. x = random(2,(mx*2)-2)
  70. y = random(2,(my*2)-2)
  71.  
  72. /* Determine starting direction */
  73. if (x < mx) then do 
  74.     xd = 1
  75.     end
  76.     else do
  77.     xd = -1
  78.     end
  79. yd = 0
  80.  
  81. lock on
  82.  
  83. /* These are for the arrow keys.  For regular keys, it would be the ASCII
  84.    code, but for rawkeys, AmiSlate adds 300 to distinguish them from other
  85.    ASCII codes. */
  86. leftkey  = 379
  87. rightkey = 378
  88. upkey    = 376
  89. downkey  = 377
  90.  
  91. /* Start with a fresh screen */
  92. clear
  93.  
  94. SetWindowTitle '"'||"And.... you're off!!!"||'"'
  95. SetRemoteWindowTitle '"'||"Remote computer just began a Surround worm!"||'"'
  96.  
  97. do while (1)
  98.     waitevent 0 stem mov. KEYPRESS
  99.     
  100.     if (mov.type = AMessage.QUIT) then do
  101.         lock off
  102.         exit
  103.         end        
  104.     
  105.     if (mov.lastkey > 0) then do
  106.         if ((xd < 1)&(mov.lastkey = leftkey)) then do
  107.             xd = -1
  108.             yd = 0
  109.             end
  110.         if ((xd > -1)&(mov.lastkey = rightkey)) then do
  111.             xd = 1
  112.             yd = 0
  113.             end
  114.         if ((yd < 1)&(mov.lastkey = upkey)) then do
  115.             xd = 0
  116.             yd = -1
  117.             end
  118.         if ((yd > -1)&(mov.lastkey = downkey)) then do
  119.             xd = 0
  120.             yd = 1
  121.             end
  122.         end
  123.         
  124.     getpixel (x+xd) (y+yd)
  125.     if ((rc = 0)|(rc2 ~= 0)) then do
  126.         SetWindowTitle '"'||"You Died! Game over!"||'"'
  127.         SetRemoteWindowTitle '"'||"You Won! The other guy just ate it!"||'"'
  128.         lock off
  129.         exit
  130.         end
  131.                 
  132.     x = x + xd
  133.     y = y + yd
  134.     
  135.     pen x y
  136. end